package com.learn.FunctionalInterface;

import java.util.function.Function;

/**
 *  接收返还型 Function<T,R>  入参出参任意值
 *
 *  Function一般使用在处理集合中
 *
 *  andthen 先执行后调用
 *  compase 先调用在执行
 *
 *  IntFunction  LongFunction  DoubleFunction   指定一种入参类型
 *  ToIntFunction ToLongFunction  ToDoubleFunction  指定一种出参类型
 *  BiFunction 多个入参
 *
 */
public class FunctionDemo {

    public static void main(String[] args) {
        Function<String,String> fun = str -> str;
        System.out.println(fun.apply("hello function"));

        // 对比andthen和compase方法
        Function<Integer,Integer> a = x->x*2;
        Function<Integer,Integer> c = x->x*x;

        //先执行后调用
        Integer apply = a.andThen(c).apply(4);
        //先调用后执行
        Integer com = a.compose(c).apply(4);
        System.out.println("andThen="+apply);
        System.out.println("com="+com);

        //identity 方法就是讲形参返回  Function.identity()  =>  Function::identity
        System.out.println("identity="+Function.identity());
    }
}
